//
//  RYDBaseApi.m
//  RTLRenYiDa
//
//  Created by 林波 on 16/9/7.
//  Copyright © 2016年 linbo1. All rights reserved.
//

#import "RYDBaseApi.h"

@implementation RYDBaseApi





-(NSDictionary*)requestHeader
{
    return self.headDictionary;
}

// 配置基础url
- (NSString*)requestBaseURL
{
    
//    return @"http://172.16.116.195:8083/";
//       return @"Http://api.douban.com/";
    return @"http://v.juhe.cn";
//    return @"http:120.27.197.205:18080/";
}

#pragma mark  - delegate

// 请求成功
-(void)requestDidFinishSuccess
{
    //判断用户的token是否失效；
    NSString *code = [self.responseObject objectForKey:@"code"];
    if ([code isKindOfClass:[NSString class]]) {
        if ([code integerValue] == 101) {
            dispatch_sync(dispatch_get_main_queue(), ^{
            });
            return;
        }
    }
    
    NSLog(@"self.responseObject = %@", self.responseObject );
    
    
    //判段下是否需要传回模型并且看下是否有值
    id  dic;
    if ([self.responInfo length]>0)
    {
        dic = [self.responseObject objectForKey:self.responInfo];
    }else
    {
        dic  = self.responseObject;
    }
     [self.baseApiDelegate responseInfo:self.responseObject requestURL:self.requestURL NetWoringSuccess:YES];
    
}
// 请求失败
- (void)requestDidFinishFailure
{
    [self.baseApiDelegate responseInfo:self.responseObject requestURL:self.requestURL NetWoringSuccess:NO];
}


// 判断字典是否为空
- (BOOL)isNullDictonary:(NSDictionary*)dic
{
    if (!dic || dic ==nil){
        return YES;
    }else{
        @try
        {
            if ([dic respondsToSelector:@selector(allKeys)]){
                NSArray * keys =[dic allKeys];
                if (keys.count>0){
                    return NO;
                }else{
                    return YES;
                }
            }else{
                return YES;
            }
        }
        @catch (NSException *exception){
            return YES;
        }
    }
}

@end
